<?php
declare(strict_types=1);

namespace App\Controller\v1;

use Throwable;
use App\Helper\Log;
use App\Helper\Util;
use App\Helper\Common;
use Hyperf\DbConnection\Db;
use App\Constants\ReturnCode;
use Hyperf\Di\Annotation\Inject;
use App\Controller\AbstractController;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Service\UserService;
use App\Middleware\Api\AuthMiddleware;

#[Controller]
#[Middleware(AuthMiddleware::class)]
class HomeController extends AbstractController
{
    #[Inject]
    protected UserService $userServ;

    #进入首页前检查用户角色、科室等
    #[RequestMapping(path: "check", methods: "post")]
    public function check(){
        $user_id = $this->request->getAttribute('user_id');
        $this->userServ->setUserId($user_id);
        $res = $this->userServ->getUserInUseOffice();
        return $this->fmt_response(ReturnCode::deal_succ, '获取成功', $res);
    }
    #首页-日历
    #[RequestMapping(path: "calendar", methods: "post")]
    public function calendar(){
        $office_id = $this->request->input("office_id", 0);
        $begin_date = $this->request->input("begin_date", "");
        $end_date = $this->request->input("end_date", "");
        $user_id = $this->request->getAttribute('user_id');
        $this->userServ->setUserId($user_id);
        $params = [
            'office_id'=>$office_id,
            'begin_date'=>$begin_date,
            'end_date'=>$end_date
        ];
        $res = $this->userServ->getUserCalendarInfo($params);
        return $this->fmt_response(ReturnCode::deal_succ, '获取成功', $res);
    }
    #某日详情
    #[RequestMapping(path: "day-detail", methods: "post")]
    public function dayDetail(){
        $office_id = $this->request->input("office_id", 0);
        $day = $this->request->input("day", "");
        $user_id = $this->request->getAttribute('user_id');
        $this->userServ->setUserId($user_id);
        $params = [
            'office_id'=>$office_id,
            'day'=>$day
        ];
        $res = $this->userServ->getUserDayInfo($params);
        return $this->fmt_response(ReturnCode::deal_succ, '获取成功', $res);
    }
}